package com.navi.loaddata.loadService.impl.Dcdata;

import com.navi.loaddata.core.etlException.ETLException;
import com.navi.loaddata.core.mesEntity.SpcDcdataEntity;
import com.navi.loaddata.core.oracleEntity.cell1.EtlCellPdsComponentV;
import com.navi.loaddata.core.util.LoggerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * @author jay
 */
@Service
public class ProcessDcDataServiceCELL1 {

    private static final Logger logger = LoggerFactory.getLogger(ProcessDcDataServiceCELL1.class);

//    public List<EtlCellPdsComponentV> processDcData(List<SpcDcdataEntity> spcDcdataEntityList,int errorProcessSpcDcdata, Logger logger) throws ETLException {
//        List<EtlCellPdsComponentV> etlCfPdsGlassVList = new ArrayList<>();
//        for(int i=0;i<spcDcdataEntityList.size();i++){
//            EtlCellPdsComponentV etlCfPdsGlassV = new EtlCellPdsComponentV();
//            try {
//                etlCfPdsGlassV = processDcData(spcDcdataEntityList.get(i), errorProcessSpcDcdata,logger);
//                etlCfPdsGlassVList.add(etlCfPdsGlassV);
//            }catch (Exception e){
//                logger.error(LoggerUtil.stackTraceToString(e));
//                throw new ETLException(e.getMessage());
//            }
//        }
//        return etlCfPdsGlassVList;
//    }

    public EtlCellPdsComponentV processDcData(SpcDcdataEntity d, int errorProcessSpcDcdata, Logger logger) throws ETLException {
        EtlCellPdsComponentV etlCfPdsGlassV = new EtlCellPdsComponentV();
        try {
            if ("A".equals(d.getMaterialname().substring(0,1))) {
                etlCfPdsGlassV.setComponentType("1");
            }else if("C".equals(d.getMaterialname().substring(0,1))) {
                etlCfPdsGlassV.setComponentType("4");
            }else{
                etlCfPdsGlassV.setComponentType("10");
            }


            etlCfPdsGlassV.setStepId(d.getProcessoperationname());
            etlCfPdsGlassV.setSubEquipId(d.getUnitname());
            etlCfPdsGlassV.setComponentId(d.getMaterialname());
            etlCfPdsGlassV.setGlassId(d.getMaterialname());
            etlCfPdsGlassV.setComponentEndTime(d.getEventtime());
            etlCfPdsGlassV.setProductId(d.getProductspecname());
            etlCfPdsGlassV.setRouteId(d.getProcessflowname());
            etlCfPdsGlassV.setGroupId(d.getLotname());
//            etlCfPdsGlassV.setLotId(d.getLotname());
            etlCfPdsGlassV.setEquipId(d.getMachinename());
            etlCfPdsGlassV.setRunMode(d.getRunmode());
            etlCfPdsGlassV.setRecipeId(d.getRecipename());
            etlCfPdsGlassV.setOperatorId(d.getEventuser());
            etlCfPdsGlassV.setOwnerId(d.getOwnercode());
            etlCfPdsGlassV.setMesLinkKry(d.getMeslinkkey());

            if ("A".equals(d.getMaterialname().substring(0,1))) {
                etlCfPdsGlassV.setArrayGlassId(d.getMaterialname());
            }else if("C".equals(d.getMaterialname().substring(0,1))){
                etlCfPdsGlassV.setCfGlassId(d.getMaterialname());
            }else{
                etlCfPdsGlassV.setCfGlassId("glass不是A,C开头");
            }

        }catch (Exception e){
            logger.error(errorProcessSpcDcdata+":"+e.getMessage());
            logger.error(LoggerUtil.stackTraceToString(e));
            throw new ETLException(errorProcessSpcDcdata+":"+e.getMessage());
        }
//        etlCfPdsGlassV.setTaShift(); todo
        return etlCfPdsGlassV;
    }

}
